package com.MSofLectures.logistic;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.MSofLectures.Entity.Lecture.Lecture;
import com.MSofLectures.Entity.Lecture.LectureImp;

public class Student extends Basic {
	private static final long serialVersionUID = 1L;
	/**
	 * @Title Student.java
	 * @Package com.logistic
	 * @author ufo
	 * 应对学生权限的web service
	 */

	private String[] lectureId;
	private String[] lecture_registerCode;

	public String deleteUser_registerLecture(){
		try{
			if(isOnline())
				addSessionToUser();
			this.result.put("flag",this.user.deleteUser_registerLecture(getLectureId()[0])?"true":"false");
		}catch(Exception e){
			e.printStackTrace();
			this.result.put("flag", "false");
		}
			return SUCCESS;
		
	}
	public String registerOneLecture() {// 报名讲座
		try {
			if (isOnline()) {
				addSessionToUser();
				this.user.registerLecture(getLectureId()[0]);
				result.put("flag", "true");
			}
		} catch (Exception e) {
			e.printStackTrace();
			result.put("flag", "false");
		}
		return SUCCESS;
	}

	public String checkLectureWithCode() {
		try {
			if (isOnline()) {
				addSessionToUser();

				if (this.user.checkLectureCode(getLecture_registerCode()[0],
						getLectureId()[0]))
					result.put("flag", "true");

			}
		} catch (Exception e) {
			e.printStackTrace();
			result.put("flag", "false");
		}
		return SUCCESS;
	}

	public String showAllRegisterLecture() {
		try {
			if (isOnline()) {
				addSessionToUser();
				List<String> list = this.user.showAllRegisterLecture();
				Iterator<String> i = list.iterator();
				int a = 0;
				for (; i.hasNext(); a++) {

					LectureImp lecturetmp = new Lecture(i.next());
					result.put("lecname" + a, lecturetmp.getValue("lecName"));
					try {
						lecturetmp.finalize();
					} catch (Throwable e) {
						// TODO 自动生成的 catch 块
						e.printStackTrace();
					}
				}
				result.put("flag", a > 0 ? "true" : "false");
			}
		} catch (Exception e) {
			e.printStackTrace();
			result.put("flag", "false");
		}
		return SUCCESS;
	}

	public String userLectureStatus() {
		try {
			if (isOnline()) {
				addSessionToUser();
				String status = this.user.userLectureStatus(getLectureId()[0]);
				String order = this.user.userOrder(getLectureId()[0],
						this.user.getUserId());
				result.put("flag", "true");
				result.put("status", status);
				result.put("order", order);
			}
		} catch (Exception e) {
			e.printStackTrace();
			result.put("flag", "false");
		}
		return SUCCESS;
	}

	public String showAllCheckLecture() {
		try {
			if (isOnline()) {
				addSessionToUser();
				List<String> list = this.user.showAllCheckLecture();
				Iterator<String> i = list.iterator();
				int a = 0;
				for (; i.hasNext(); a++) {
					LectureImp lecturetmp = new Lecture(i.next());
					result.put("lecname" + a, lecturetmp.getValue("lecName"));
					try {
						lecturetmp.finalize();
					} catch (Throwable e) {
						// TODO 自动生成的 catch 块
						e.printStackTrace();
					}
				}
				result.put("flag", a > 0 ? "true" : "false");
			}
		} catch (Exception e) {
			e.printStackTrace();
			result.put("flag", "false");
		}
		return SUCCESS;
	}

	@Override
	public Map<String, String> getResult() {
		// TODO 自动生成的方法存根
		return this.result;
	}

	public String[] getLectureId() {
		return lectureId;
	}

	public void setLectureId(String[] lectureId) {
		this.lectureId = lectureId;
	}

	public String[] getLecture_registerCode() {
		return lecture_registerCode;
	}

	public void setLecture_registerCode(String[] lecture_registerCode) {
		this.lecture_registerCode = lecture_registerCode;
	}

}
